package org.gp.Interfaz;

import javax.swing.JDialog;

import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.SwingConstants;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.FlowLayout;
import javax.swing.JPanel;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Iterator;

import org.gp.tringes.GestorIGInicio;
import org.gp.tringes.GestorIGSeleccionClubaModificar;

import javax.swing.JComboBox;
import java.awt.Font;


public class IGSeleccionarClubaModificar extends JDialog {
	
	private JPanel panel;
	private JPanel panel_1;
	private JButton btnAceptar;
	private JButton btnCancelar;
	private JPanel panel_2;
	private JPanel panel_3;
	private JPanel panel_4;
	private JPanel panel_5;
	private JPanel panel_6;
	private JLabel lblEligeElClub;
	private JComboBox comboClubes;
	
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					IGSeleccionarClubaModificar dialog = new IGSeleccionarClubaModificar();
					dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
					dialog.setVisible(true);
					dialog.setModal(true);
					dialog.setResizable(false);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
	
	public IGSeleccionarClubaModificar() {
		setBounds(100, 100, 415, 186);
		//ID-197
		setTitle(GestorIGInicio.getGestorIGInicio().getTexto(197));
		getContentPane().setLayout(new BorderLayout(0, 0));
		getContentPane().add(getPanel(), BorderLayout.NORTH);
		getContentPane().add(getPanel_1(), BorderLayout.SOUTH);
		getContentPane().add(getPanel_2(), BorderLayout.CENTER);
		getContentPane().add(getPanel_3(), BorderLayout.WEST);
		getContentPane().add(getPanel_4(), BorderLayout.EAST);
	}
	
	//Metodo Cargar Clubes para que tras modificar el nombre de un club este aparezca cambiado.
		private void cargarClubes(){
			String club;
			Iterator<String> itr= GestorIGSeleccionClubaModificar.getGestorIGSeleccionClubaModificar().obtenerClubes();
			while(itr.hasNext()) {
				club = itr.next();
				comboClubes.addItem(club);
			}
		
		}
	
	/*********
	 * Combos
	 *
	 *********/
	
	private JComboBox getComboClubes() {
		if (comboClubes == null) {
			comboClubes = new JComboBox();
			cargarClubes();
		}
		return comboClubes;
	}
	
	/*********
	 * Botones
	 *
	 *********/
	
	private JButton getBtnAceptar(){
		if(btnAceptar == null){
			//ID-2
			btnAceptar = new JButton(GestorIGInicio.getGestorIGInicio().getTexto(2));
			btnAceptar.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent arg0) {
					String nombreClub=(String) comboClubes.getSelectedItem();

					if(nombreClub!=null){
					setVisible(false);
					JDialog espera = new IGEspera();
					espera.setLocationRelativeTo(null);
					espera.setVisible(true);
					JDialog datosClub = new IGDatosClub(GestorIGSeleccionClubaModificar.getGestorIGSeleccionClubaModificar().obtenerIdClub(nombreClub));
					datosClub.setResizable(false);
					datosClub.setModal(true);
					datosClub.setLocationRelativeTo(null);
					espera.dispose();
					datosClub.setVisible(true);
					comboClubes.removeAllItems();
					cargarClubes();
					setVisible(true);
					}else{
						//ID-65 y 4
						JOptionPane.showMessageDialog(null, GestorIGInicio.getGestorIGInicio().getTexto(65), GestorIGInicio.getGestorIGInicio().getTexto(4), JOptionPane.WARNING_MESSAGE);
					}
				
				}
			});
		}
		return btnAceptar;
	}
	
	
	private JButton getBtnCancelar(){
		if(btnCancelar == null){
			//ID-8
			btnCancelar = new JButton(GestorIGInicio.getGestorIGInicio().getTexto(8));
			btnCancelar.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent arg0) {
					dispose();
				}
			});
		}
		return btnCancelar;
	}
	
	/***********
	 * Etiquetas
	 *
	 **********/
	
	private JLabel getLblEligeElClub() {
		if (lblEligeElClub == null) {
			//ID-198
			lblEligeElClub = new JLabel(GestorIGInicio.getGestorIGInicio().getTexto(198));
			lblEligeElClub.setFont(new Font("Tahoma", Font.PLAIN, 13));
			lblEligeElClub.setHorizontalAlignment(SwingConstants.LEFT);
		}
		return lblEligeElClub;
	}
	
	
	/*********
	 * Paneles
	 *
	 *********/
	private JPanel getPanel(){
		if(panel == null){
			panel = new JPanel();
			panel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 15));
		}
		return panel;
	}
	
	private JPanel getPanel_1(){
		if(panel_1 == null){
			panel_1 = new JPanel();
			panel_1.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 10));
			panel_1.add(getBtnAceptar());
			panel_1.add(getBtnCancelar());
		}
		return panel_1;
	}
	private JPanel getPanel_2() {
		if (panel_2 == null) {
			panel_2 = new JPanel();
			panel_2.setLayout(new BorderLayout(0, 0));
			panel_2.add(getPanel_5(), BorderLayout.NORTH);
			panel_2.add(getPanel_6(), BorderLayout.SOUTH);
			panel_2.add(getComboClubes(), BorderLayout.CENTER);
		}
		return panel_2;
	}

	private JPanel getPanel_3() { // Este panel se ha usado para rellenar huecos en la pantalla
		if (panel_3 == null) {
			panel_3 = new JPanel();
			FlowLayout flowLayout = (FlowLayout) panel_3.getLayout();
			flowLayout.setHgap(40);
		}
		return panel_3;
	}
	private JPanel getPanel_4() { // Este panel se ha usado para rellenar huecos en la pantalla
		if (panel_4 == null) {
			panel_4 = new JPanel();
			FlowLayout flowLayout = (FlowLayout) panel_4.getLayout();
			flowLayout.setHgap(40);
		}
		return panel_4;
	}

	private JPanel getPanel_5() { 
		if (panel_5 == null) {
			panel_5 = new JPanel();
			FlowLayout flowLayout = (FlowLayout) panel_5.getLayout();
			flowLayout.setVgap(10);
			panel_5.add(getLblEligeElClub());
		}
		return panel_5;
	}
	
	
	
	private JPanel getPanel_6() { // Este panel se ha usado para rellenar huecos en la pantalla
		if (panel_6 == null) {
			panel_6 = new JPanel();
			FlowLayout flowLayout = (FlowLayout) panel_6.getLayout();
			flowLayout.setVgap(10);
		}
		return panel_6;
	}
	
}